package com.et.u1.vm.pay;

import android.annotation.SuppressLint;

import androidx.lifecycle.ViewModel;

import com.et.core.goods.GoodsInfo;
import com.et.u1.BuildConfig;
import com.et.u1.util.ApiProvider;
import com.et.u1.util.DataKt;
import com.et.u1.util.Detail;
import com.et.u1.util.HttpUse;
import com.et.u1.util.Result;
import com.et.u1.util.Rows;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;

public class PayViewModel extends ViewModel {
    private final String PAY_FOR_QRCODE = BuildConfig.QR_code_service;
    private final String myappidMvv = BuildConfig.myappidMvv;


    public Result payForQR_code(GoodsInfo goodsInfo) {

        String pay_type = "41";
        @SuppressLint("DefaultLocale")
        Rows rows = new Rows(
                String.format("%02d", goodsInfo.getChannel().getBox()),
                String.format("%02d", goodsInfo.getChannel().getChannel()),
                DataKt.getUuid(),
                String.valueOf(goodsInfo.getChannel().getPrice() * goodsInfo.getDiscount() / 10000f),
                goodsInfo.getName(),
                goodsInfo.getBarcode(),
                String.valueOf(goodsInfo.getDiscount()),
                goodsInfo.getChannel().getLabel(),
                "1");
        ArrayList<Rows> list = new ArrayList<>();
        list.add(rows);

        Detail detail = new Detail(DataKt.getUuid(), DataKt.getBorad(), list);

        String time = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()).format(System.currentTimeMillis());
        HashMap<String, String> map = new HashMap<>();
        map.put("avm", DataKt.getUuid());
        map.put("pay_type", pay_type);
        map.put("datetime", time);
        map.put("detail", detail.toString());
        map.put("myappid", myappidMvv);
        Result result = new Result();
        new HttpUse.Post(ApiProvider.MVV, result).putUrl(PAY_FOR_QRCODE)
                .putParam(map).base64(true)
                .build().execute();
        return result;
    }


}